package com.yxq.mdt.app.modules.auction.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.orhanobut.hawk.Hawk;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.base.BaseActivity;
import com.yxq.mdt.app.constant.SPKey;
import com.yxq.mdt.app.modules.auction.bean.HonorValueBean;
import com.yxq.mdt.app.modules.auction.model.AuctionModel;
import com.yxq.mdt.app.modules.main.bean.NameAndPhoneBean;
import com.yxq.mdt.app.modules.pm.ui.PmGoodsDetailTabVerticalActivity;
import com.yxq.mdt.app.net.ApiModel;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 申请为预备团长页面
 */
public class PreTeamLeaderIntroActivity extends BaseActivity {


    @BindView(R.id.become_go_give)
    TextView becomeGoGive;
    @BindView(R.id.become_check_box)
    CheckBox becomeCheckBox;
    @BindView(R.id.become_check_agreement)
    TextView becomeCheckAgreement;
    @BindView(R.id.become_team_leader_quick)
    TextView becomeTeamLeaderQuick;
    @BindView(R.id.become_team_leader)
    TextView becomeTeamLeader;
    @BindView(R.id.become_money)
    TextView becomeMoney;

    @Override
    public int getLayoutId() {
        return R.layout.activity_team_leader_pre_intro;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
    }

    @OnClick({R.id.become_team_leader_quick, R.id.become_team_leader, R.id.become_go_give})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.become_go_give:
            case R.id.become_team_leader_quick:
                //添加礼包入口
                NameAndPhoneBean nameAndPhoneBean = Hawk.get(SPKey.SP_KEY_NAME_PHONE_INFO);
                Intent intent = new Intent(mActivity, PmGoodsDetailTabVerticalActivity.class);
                intent.putExtra("id", nameAndPhoneBean.getSmallBag().getGift_goods_id());
                intent.putExtra("goodsType", 1);
                startActivity(intent);
                break;
            case R.id.become_team_leader:
                intent = new Intent(mActivity, PreLeaderApplyActivity.class);
                startActivity(intent);
                break;

        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        status();
        getPrepared();
    }

    /**
     * 收益状态
     */
    private void status() {
        AuctionModel.getCountWithLevelone(new ApiModel.CommonCallback<String>() {
            @Override
            public void onSuccess(String honorValueBean) {
                JSONObject jsonObject = JSON.parseObject(honorValueBean);
                becomeMoney.setText("您当前直推粉丝数：" + jsonObject.getIntValue("number"));

            }

            @Override
            public void onError(String errMsg) {

            }
        });
    }

    /**
     * 申请状态
     */
    private void getPrepared() {
        AuctionModel.getPrepared(new ApiModel.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {

                JSONObject jsonObject = JSON.parseObject(result);
                //state： -1 未申请过预备团长记录 0 预备团长申请中 2 预备团长申请未通过
                int state = jsonObject.getIntValue("state");
                if (0 == state) {
                    becomeTeamLeader.setText("审核中，请耐心等待");
                    becomeTeamLeader.setEnabled(false);
                    becomeTeamLeaderQuick.setVisibility(View.GONE);
                } else {
                    becomeTeamLeader.setEnabled(true);
                    becomeTeamLeader.setText("免费申请为预备团长");
                    becomeTeamLeaderQuick.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void onError(String errMsg) {

            }
        });
    }
}
